var _controller = CTX + '/sys/log';
var Req = {
    list: {method: 'GET', url: _controller}
};

var $grid = null;

$(function () {

    $grid = $('#logGrid');

    initLogGrid();

    $('#searchBtn').click(function () {
        var params = getQueryParams();
        $grid.datagrid('load', params);
    });

    $('#resetBtn').click(function () {
        $('#searchForm').form('reset');
        $('#searchBtn').trigger('click');
    });
});

// 格式化DateTimeBox的时间
function fmtDateTime(date) {
    return moment(date).format('YYYY-MM-DD HH:mm:ss');
}

function getQueryParams() {
    var params = $('#searchForm').serializeForm();
    return params;
}

function initLogGrid() {
    $grid.datagrid({
        fit: true,
        fitColumns: true,
        nowrap: false,
        // multiSort: true,
        method: Req.list.method,
        url: Req.list.url,
        queryParams: getQueryParams(),
        sortName: 'createDate',
        sortOrder: 'desc',
        columns: [[{
            field: 'id',
            title: 'id',
            width: 50,
            hidden: true
        }, {
            field: 'type',
            title: '日志类型',
            width: 100
        }, {
            field: 'title',
            title: '标题',
            width: 100
        }, {
            field: 'createBy',
            title: '操作人',
            width: 100
        }, {
            field: 'createDate',
            title: '操作时间',
            width: 120,
            sortable: true
        }, {
            field: 'remoteAddr',
            title: '操作IP',
            width: 100
        }, {
            field: 'userAgent',
            title: '浏览器信息',
            width: 200
        }, {
            field: 'requestUri',
            title: '请求路径',
            width: 100
        }, {
            field: 'method',
            title: '请求方式',
            width: 50
        }, {
            field: 'params',
            title: '请求参数',
            width: 200
        }]]
    });
}


